home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / libs / x / xview / xview3.004 / xview3 / usr / openwin / include / pixrect / pixrect.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-30  |  10.5 KB  |  336 lines

  1. /* @(#)pixrect.h 1.50 89/07/10 SMI */
  2. /*
  3.  * Copyright 1986-89 by Sun Microsystems, Inc.
  4.  */
  5.  
  6. #ifndef    _pixrect_pixrect_h
  7. #define    _pixrect_pixrect_h
  8.  
  9. #include    <sys/types.h>    /* system type defs */
  10.  
  11. /*
  12.  * This file defines the programmer interface to the pixrect abstraction.
  13.  * A pixrect is a rectangular array of pixels on which a number of
  14.  * operations are defined.
  15.  *
  16.  * Each pixrect has as visible attributes its height and width in
  17.  * pixels and the number of bits stored for each pixel.  It also supports
  18.  * several operations.  The proper way to think of the operations is
  19.  * that they are messages sent to the pixrect.  The operations are:
  20.  *
  21.  *    pr_destroy    Destroy a pixrect.
  22.  *    pr_rop        Raster operation from another pixrect to the
  23.  *            destination pixrect.  The case where the source
  24.  *            and destination overlap is properly handled.
  25.  *    pr_stencil    Raster operation from source pixrect to the
  26.  *            dest pixrect using a stencil pixrect as a 'cookie
  27.  *            cutter' to perform a spatial write enable.
  28.  *    pr_batchrop    Like pr_rop, but source is an array of pixrects,
  29.  *            and an offset to be applied before each pixrect.
  30.  *            This is specifically designed for operations like
  31.  *            putting up text, which consists of a number of
  32.  *            characters from a font, each given by a pixrect.
  33.  *    pr_get        Get the value of a single pixel from a pixrect.
  34.  *    pr_put        Change a single pixel value in a pixrect.
  35.  *    pr_vector    Draw a vector in a pixrect
  36.  *    pr_region    Create a new pixrect which describes a rectangular
  37.  *            sub-region of an existing pixrect.
  38.  *    pr_putcolormap    Write a portion of the colormap.
  39.  *    pr_getcolormap    Read a portion of the colormap.
  40.  *    pr_putattributes Set the plane mask.
  41.  *    pr_getattributes Get the plane mask.
  42.  */
  43.  
  44. /*
  45.  * There are a number of structures used in the arguments to pixrects:
  46.  *
  47.  *    struct pr_pos        A position within a pixrect is a pair of
  48.  *                integers giving the offset from the upper
  49.  *                left corner.  The pixels within a pixrect
  50.  *                are numbered with (0,0) at the upper left
  51.  *                and (width-1,height-1) at the lower right.
  52.  *    struct pr_prpos        A pixrect and a position within it.
  53.  *    struct pr_size        A pair of integers representing the
  54.  *                size of a rectangle within a pixrect.
  55.  *    struct pr_subregion    A pixrect, a position and a size,
  56.  *                specifying a rectangular sub-region.
  57.  */
  58.  
  59. struct pr_size {
  60.     int    x, y;
  61. };
  62.  
  63. typedef struct pixrect {
  64.     struct    pixrectops *pr_ops;    /* operations appropriate to this pr */
  65.     struct    pr_size pr_size;    /* pixels per dimension */
  66.     int    pr_depth;        /* bits per pixel */
  67.     caddr_t    pr_data;        /* device-dependent data */
  68. } Pixrect;
  69. #define pr_width    pr_size.x
  70. #define pr_height    pr_size.y
  71.  
  72. struct pr_pos {
  73.     int    x, y;
  74. };
  75.  
  76. struct pr_prpos {
  77.     Pixrect *pr;
  78.     struct    pr_pos pos;
  79. };
  80.  
  81. struct pr_subregion {
  82.     Pixrect *pr;
  83.     struct    pr_pos pos;
  84.     struct    pr_size size;
  85. };
  86.  
  87. /*
  88.  * Pr_product is used when doing multiplications involving pixrects,
  89.  * and casts its arguments to that the compiler will use 16 by 16 multiplies.
  90.  */
  91. #ifndef pr_product
  92. #if defined(sun) && !defined(sparc)
  93. #define    pr_product(a, b)    ((short)(a) * (short)(b))
  94. #else
  95. #define    pr_product(a, b)    ((a) * (b))
  96. #endif
  97. #endif
  98.  
  99. #ifndef KERNEL
  100. /*
  101.  * Takes device file name.  This is how a screen pixrect is created.
  102.  */
  103. extern Pixrect *pr_open();
  104. #endif !KERNEL
  105.  
  106. /*
  107.  * Pixrect ops vector, used by pr_ macros below to call the appropriate
  108.  * device dependent function for the destination pixrect.
  109.  */
  110. struct pixrectops {
  111.     int    (*pro_rop)();
  112. #ifndef KERNEL
  113.     int    (*pro_stencil)();
  114.     int    (*pro_batchrop)();
  115.     int    (*pro_nop)();        /* place holder */
  116.     int    (*pro_destroy)();
  117.     int    (*pro_get)();
  118.     int    (*pro_put)();
  119.     int    (*pro_vector)();
  120.     Pixrect * (*pro_region)();
  121. #endif !KERNEL
  122.     int    (*pro_putcolormap)();
  123. #ifndef KERNEL
  124.     int    (*pro_getcolormap)();
  125. #endif !KERNEL
  126.     int    (*pro_putattributes)();
  127. #ifndef KERNEL
  128.     int    (*pro_getattributes)();
  129. #endif !KERNEL
  130. #ifdef KERNEL
  131.     int    (*pro_nop)();        /* place holder */
  132. #endif KERNEL
  133. };
  134.  
  135. #if !defined(lint) || defined(KERNEL)
  136.  
  137. #define    pr_rop(dpr, dx, dy, w, h, op, spr, sx, sy) \
  138.     (*(dpr)->pr_ops->pro_rop)((dpr), (dx), (dy), (w), (h), (op), \
  139.         (spr), (sx), (sy))
  140. #define    pr_putcolormap(pr, ind, cnt, red, grn, blu) \
  141.     (*(pr)->pr_ops->pro_putcolormap)((pr), (ind), (cnt), \
  142.         (red), (grn), (blu))
  143. #define    pr_putattributes(pr, planes) \
  144.     (*(pr)->pr_ops->pro_putattributes)((pr), (planes))
  145. #define _PR_IOCTL_KERNEL_DEFINED
  146. #define pr_ioctl(pr, cmd, data) \
  147.     ((pr)->pr_ops->pro_nop ? (*(pr)->pr_ops->pro_nop)((pr), (cmd), (data)) : -1)
  148.  
  149. #ifndef KERNEL
  150.  
  151. #define    pr_stencil(dpr, dx, dy, w, h, op, stpr, stx, sty, spr, sx, sy) \
  152.     (*(dpr)->pr_ops->pro_stencil)((dpr), (dx), (dy), (w), (h), (op), \
  153.         (stpr), (stx), (sty), (spr), (sx), (sy))
  154. #define    pr_batchrop(dpr, x, y, op, sbp, n) \
  155.     (*(dpr)->pr_ops->pro_batchrop)((dpr), (x), (y), (op), (sbp), (n))
  156. #define    pr_destroy(pr) \
  157.     (*(pr)->pr_ops->pro_destroy)(pr)
  158. #define    pr_get(pr, x, y) \
  159.     (*(pr)->pr_ops->pro_get)((pr), (x), (y))
  160. #define    pr_put(pr, x, y, val) \
  161.     (*(pr)->pr_ops->pro_put)((pr), (x), (y), (val))
  162. #define    pr_vector(pr, x0, y0, x1, y1, op, color) \
  163.     (*(pr)->pr_ops->pro_vector)((pr), (x0), (y0), (x1), (y1), (op), \
  164.         (color))
  165. #define    pr_region(pr, x, y, w, h) \
  166.     (*(pr)->pr_ops->pro_region)((pr), (x), (y), (w), (h))
  167. #define    pr_getcolormap(pr, ind, cnt, red, grn, blu) \
  168.     (*(pr)->pr_ops->pro_getcolormap)((pr), (ind), (cnt), \
  169.         (red), (grn), (blu))
  170. #define    pr_getattributes(pr, planes) \
  171.     (*(pr)->pr_ops->pro_getattributes)((pr), (planes))
  172. #endif !KERNEL
  173.  
  174. #else !lint || KERNEL
  175.  
  176. extern pr_rop();
  177. extern pr_stencil();
  178. extern pr_batchrop();
  179. extern pr_destroy();
  180. extern pr_get();
  181. extern pr_put();
  182. extern pr_vector();
  183. extern Pixrect *pr_region();
  184. extern pr_putcolormap();
  185. extern pr_getcolormap();
  186. extern pr_putattributes();
  187. extern pr_getattributes();
  188.  
  189. #endif lint
  190.  
  191. /*
  192.  * Several of the above operations return a common, distinguished value when
  193.  * an error arises.  That value is defined as follows:
  194.  */
  195. #define    PIX_ERR    -1
  196.  
  197. /*
  198.  * Operations.  The 'op' in 'rasterop' may be any binary Boolean function, 
  199.  * encoded as an integer from 0 to 15 (the op code) shifted left by one bit.  
  200.  * The function is applied per-pixel.  
  201.  *
  202.  * The following permit the op to be expressed as Boolean combinations
  203.  * of the two inputs 'src' and 'dst'.  Thus oring the source and destination
  204.  * together is written as PIX_SRC|PIX_DST, while xoring the source with the
  205.  * destination is PIX_SRC^PIX_DST.  Since ~op would set the color and clip
  206.  * bits, the macro PIX_NOT is provided for use in place of ~.
  207.  */
  208. #define    PIX_SRC        (0xC << 1)
  209. #define    PIX_DST        (0xA << 1)
  210. #define    PIX_NOT(op)    ((op) ^ 0x1E)
  211. #define    PIX_CLR        (0x0 << 1)
  212. #define    PIX_SET        (0xF << 1)
  213.  
  214. /* macros which tell whether a rasterop needs SRC or DST values */
  215. #define    PIXOP_NEEDS_DST(op)    ((((op)>>1)^(op)) & PIX_NOT(PIX_DST))
  216. #define    PIXOP_NEEDS_SRC(op)    ((((op)>>2)^(op)) & PIX_NOT(PIX_SRC))
  217.  
  218. /* macros for encoding and extracting color field */
  219. #define    PIX_COLOR(c)    ((c)<<5)
  220. #define    PIX_OPCOLOR(op)    ((op)>>5)
  221. #define PIX_OP_CLIP(op)    ((op)&0x1f)
  222. #define PIX_OP(op)    ((op)&0x1e)
  223.  
  224. /*
  225.  * The pseudo-operation PIX_DONTCLIP specifies that clipping should not
  226.  * be performed.  PIX_CLIP is also provided, although unnecessary.
  227.  */
  228. #define    PIX_DONTCLIP        0x1
  229. #define    PIX_CLIP        0x0
  230.  
  231. /*
  232.  * The following structured definitions, all prefixed with prs_, correspond
  233.  * to the unstructured definitions above prefixed with pr_.
  234.  */
  235.  
  236. #if !defined(lint) || defined(KERNEL)
  237.  
  238. #define    prs_rop(dstreg, op, srcprpos) \
  239.     pr_rop((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  240.         (dstreg).size.x, (dstreg).size.y, (op), \
  241.         (srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  242. #define    prs_stencil(dstreg, op, stenprpos, srcprpos) \
  243.     pr_stencil((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  244.         (dstreg).size.x, (dstreg).size.y, (op), \
  245.         (stenprpos).pr, (stenprpos).pos.x, (stenprpos).pos.y, \
  246.         (srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  247. #define    prs_batchrop(dstprpos, op, items, n) \
  248.     pr_batchrop((dstprpos).pr, (dstprpos).pos.x, (dstprpos).pos.y, \
  249.         (op), (items), (n))
  250. #define    prs_destroy(pr)        pr_destroy(pr)
  251. #define    prs_get(srcprpos) \
  252.     pr_get((srcprpos).pr, (srcprpos).pos.x, (srcprpos).pos.y)
  253. #define    prs_put(dstprpos, val) \
  254.     pr_put((dstprpos).pr, (dstprpos).pos.x, (dstprpos).pos.y, (val))
  255. #define    prs_vector(pr, pos0, pos1, op, color) \
  256.     pr_vector((pr), (pos0).x, (pos0).y, (pos1).x, (pos1).y, (op), (color))
  257. #define    prs_region(dstreg) \
  258.     pr_region((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  259.         (dstreg).size.x, (dstreg).size.y)
  260. #define    prs_putcolormap(pr, ind, cnt, red, grn, blu) \
  261.     pr_putcolormap((pr), (ind), (cnt), (red), (grn), (blu))
  262. #define    prs_getcolormap(pr, ind, cnt, red, grn, blu) \
  263.     pr_getcolormap((pr), (ind), (cnt), (red), (grn), (blu))
  264. #define    prs_putattributes(pr, planes)    pr_putattributes((pr), (planes))
  265. #define    prs_getattributes(pr, planes)    pr_getattributes((pr), (planes))
  266.  
  267. /* pr_replrop is not currently in the ops vector */
  268. #define    prs_replrop(dstreg, op, srcprpos) \
  269.     pr_replrop((dstreg).pr, (dstreg).pos.x, (dstreg).pos.y, \
  270.         (dstreg).size.x, (dstreg).size.y, (op), \
  271.         (srcprpos).pr, (srcprpos).pos.x , (srcprpos).pos.y )
  272.  
  273. /* pr_close is a synonym for pr_destroy */
  274. #define    pr_close(pr)    pr_destroy(pr)
  275.  
  276. /* textured line macro */
  277. #define    pr_line(pr, x0, y0, x1, y1, brush, tex, op) \
  278.     pro_line((pr), (x0), (y0), (x1), (y1), (brush), (tex), (op), 0) 
  279.  
  280. #else !lint || KERNEL
  281.  
  282. extern prs_rop();
  283. extern prs_stencil();
  284. extern prs_batchrop();
  285. extern prs_destroy();
  286. extern prs_get();
  287. extern prs_put();
  288. extern prs_vector();
  289. extern Pixrect *prs_region();
  290. extern prs_putcolormap();
  291. extern prs_getcolormap();
  292. extern prs_putattributes();
  293. extern prs_getattributes();
  294.  
  295. extern prs_replrop();
  296. extern pr_close();
  297. extern pr_line();
  298.  
  299. #endif !lint || KERNEL
  300.  
  301.  
  302.  
  303. /*
  304.  * magic flag passed to true color frame buffer to force updating the
  305.  * colormap.  Yes, a kludge.
  306.  * Value defined to be the same as PIX_DONT_SET_PLANES purposedly
  307.  */
  308. #define    PR_FORCE_UPDATE    (1 << 24)
  309. #ifndef ROUNDUP
  310. #define ROUNDUP(val, gran)      (((val) - 1 | (gran) - 1) + 1)
  311. #endif
  312.  
  313. /* structure used to specify fields in a 32-bit pixel */
  314. union fbunit {
  315.     unsigned int    packed;           /* whole-sale deal */
  316.     struct {
  317.     unsigned int    A:8;           /* unused, for now */
  318.     unsigned int    B:8;           /* blue channel */
  319.     unsigned int    G:8;           /* green channel */
  320.     unsigned int    R:8;           /* red channel */
  321.     }               channel;           /* access per channel */
  322. };
  323.  
  324. #define    pr_putlut(pr, ind, cnt, red, grn, blu) \
  325.     (*(pr)->pr_ops->pro_putcolormap)((pr), PR_FORCE_UPDATE | (ind), \
  326.         (cnt), (red), (grn), (blu))
  327.  
  328. #ifndef KERNEL
  329. #define    pr_getlut(pr, ind, cnt, red, grn, blu) \
  330.     (*(pr)->pr_ops->pro_getcolormap)((pr), PR_FORCE_UPDATE | (ind), \
  331.         (cnt), (red), (grn), (blu))
  332. #endif !KERNEL
  333.  
  334.  
  335. #endif    /* !_pixrect_pixrect_h */
  336.